package com.zhang.modules.api.entity;

import com.zhang.common.jpa.entity.BaseEntity;
import com.zhang.principal.ApiInfo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;


@Data
@Entity
@NoArgsConstructor
@Table(name ="sys_acl_api")
public class Api extends BaseEntity implements ApiInfo {

    @Column(name = "name", nullable = false, length = 64)
    @ApiModelProperty("接口名称")
    private String name;

    @Column(name = "gid",nullable = false, length = 20)
    @ApiModelProperty("接口组id")
    private String pid;

    @Column(name = "path", length = 128)
    @ApiModelProperty("接口路径")
    private String path;

    @Column(name = "anonymous")
    @ApiModelProperty("是否允许匿名访问")
    private Boolean anonymous;

    @Column(name = "status", nullable = false, length = 32)
    @ApiModelProperty("状态-正常，隐藏，禁用")
    private String status;

    @Column(name = "sort", nullable = false)
    @ApiModelProperty("接口排序")
    private Integer sort;

    @Column(name = "api_group", nullable = false)
    @ApiModelProperty("是否是接口组")
    private Boolean apiGroup;

    @Column(name = "permission_code", length = 128)
    @ApiModelProperty("权限编码")
    private String code;

    @Override
    public boolean isAnonymous() {
        return getAnonymous();
    }

    @Override
    public String getPermissionCode() {
        return code;
    }
}
